package com.homework.ch082;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/10
 */
public class Test8_DivisionByZero {
    public static void divisionA() {
        try {
            int result = 10 / 0;
            System.out.println("结果是: " + result);
        } catch (ArithmeticException e) {
            System.out.println("在divisionA方法中捕获到异常: " + e.getMessage());
            System.out.println("不能除以零！");
        }
    }

    public static void divisionB() throws ArithmeticException {
        int result = 10 / 0;
        System.out.println("结果是: " + result);
    }

    public static void main(String[] args) {
        divisionA();

        System.out.println();


        try {
            divisionB();
        } catch (ArithmeticException e) {
            // 在main方法中捕获并处理从divisionB()抛出的异常
            System.out.println("在main方法中捕获到异常: " + e.getMessage());
            System.out.println("除法运算出错：除数不能为零！");
        }

        System.out.println("程序继续正常执行...");
    }
}